/*
 * @Description:
 * @Version: 2.0
 * @Autor: zhangjx
 * @Date: 2023-05-25 11:53:13
 * @LastEditors: uphldjx 1373577124@qq.com
 * @LastEditTime: 2024-07-12 10:42:29
 */
import { encryption } from '@/utils/encdecrpt'

const adminModel = (request) => {
	return {
		loginByUsername(query: any) {
			return request('/auth/oauth/token', {
				method: 'post',
				headers: {
					isToken: false,
					'TENANT-ID': '',
					username: query.username,
					'Content-Type': 'application/x-www-form-urlencoded',
					Authorization: 'Basic YXBsaWQ6MUlhb21BTWJGajI3d0prWA==',
				},
				params: {
					grant_type: 'password',
				},
				data: query,
			})
		},
		userLogout() {
			return request('/auth/token/logout', {
				method: 'delete',
			})
		},
		uploadFile(query, onUploadProgress) {
			return request('/admin/obs/uploadFile', {
				method: 'post',
				data: query,
				headers: {
					'Content-Type': 'multipart/form-data; boundary=something',
				},
				onUploadProgress,
			})
		},
		// 一站办上传视频
		ost_uploadFile(query, onUploadProgress) {
			return request('/admin/obs/videoFormatUploadFile', {
				method: 'post',
				data: query,
				headers: {
					'Content-Type': 'multipart/form-data; boundary=something',
				},
				onUploadProgress,
			})
		},
		// 一站办养老视上传
		ost_uploadFile2(query, onUploadProgress) {
			return request('/admin/obs/uploadFile2', {
				method: 'post',
				data: query,
				headers: {
					'Content-Type': 'multipart/form-data; boundary=something',
				},
				onUploadProgress,
			})
		},
		// 文件预览下载
		previewFileDowload(fileName, onUploadProgress) {
			return request(`/admin/obs/download/${fileName}`, {
				method: 'get',
				responseType: 'blob',
				onUploadProgress,
			})
		},
		// 文件下载
		downloadFile(url, params = {}) {
			return request(url, {
				method: 'post',
				responseType: 'blob',
			})
		},
		// 系统日志
		view_sysDataOperateLog_page(query) {
			return request('/admin/sysDataOperateLog/page', {
				method: 'post',
				data: query,
			})
		},
		// 补贴工作台待办事项分页(消息通知)
		view_todo_page(query) {
			return request('/admin/sysNoticeRecord/todo/page', {
				method: 'post',
				data: query,
			})
		},
		// 删除obs中的对应图片
		view_obs_delete(fileName) {
			return request(`/admin/obs/delete/${fileName}`, {
				method: 'get',
			})
		},
	}
}
// 用户模块
const userModel = (request) => {
	return {
		// 安全员用户列表
		getSecurityUserPage(query = {}) {
			return request('/admin/user/page/security', {
				method: 'post',
				data: query,
			})
		},
		// 用户信息
		sys_user_value() {
			return request('/admin/user/info', {
				method: 'get',
			})
		},
		// 用户列表
		sys_user_querypage(query = {}) {
			return request('/admin/user/page', {
				method: 'post',
				data: query,
			})
		},
		sys_user_add(query = {}) {
			const user = encryption({
				data: query,
				param: ['password'],
			})
			return request('/admin/user', {
				method: 'post',
				data: user,
			})
		},
		sys_user_edit(query = {}) {
			const user = encryption({
				data: query,
				param: ['password'],
			})
			return request('/admin/user', {
				method: 'put',
				data: user,
			})
		},
		// 编辑用户信息
		sys_user_edit_user(query = {}) {
			return request('/admin/user/editUser', {
				method: 'post',
				data: query,
			})
		},
		sys_user_delete(ids) {
			return request('/admin/user/deleteByIds', {
				method: 'post',
				data: ids,
			})
		},
		sys_user_export(query) {
			const params = {
				...query,
				userIdList: query.idList,
				idList: undefined,
			}
			return request('/admin/user/sysuser/export', {
				method: 'post',
				data: params,
			})
		},
		// 忘记密码
		sys_user_changePwd(query) {
			const user = encryption({
				data: query,
				param: ['password'],
			})
			const params = encryption({
				data: query,
				param: ['confirmPassword'],
			})
			return request('/admin/user/changePwd', {
				method: 'post',
				data: {
					...params,
					password: user.password,
				},
			})
		},
		// 修改密码
		sys_user_changePwdSimple(query) {
			const { originalPassword } = encryption({
				data: query,
				param: ['originalPassword'],
			})
			const { password } = encryption({
				data: query,
				param: ['password'],
			})
			const { confirmPassword } = encryption({
				data: query,
				param: ['confirmPassword'],
			})
			return request('/admin/user/changePwdSimple', {
				method: 'post',
				data: {
					originalPassword,
					password,
					confirmPassword,
				},
			})
		},
		// 发送验证码
		sendVerificationCode(query) {
			return request('/admin/user/sendVerificationCode', {
				method: 'post',
				data: query,
			})
		},
		// 修改用户手机号
		sys_user_changePhone(query) {
			console.log(query, 'query')
			const { originalPassword } = encryption({
				data: query,
				param: ['originalPassword'],
			})
			return request('/admin/user/changePhone', {
				method: 'post',
				data: {
					...query,
					originalPassword,
				},
			})
		},
	}
}
// 角色
const roleModel = (request) => {
	return {
		sys_role_perm(query = {}) {
			return request('/admin/role/menu', {
				method: 'put',
				data: query,
			})
		},
		sysRoleGetMenuIds(query = {}) {
			return request('/admin/role/getMenuIds', {
				method: 'get',
				params: query,
			})
		},
		sys_role_page(query = {}) {
			return request('/admin/role/page', {
				method: 'post',
				data: query,
			})
		},
		sys_role_add(query = {}) {
			return request('/admin/role', {
				method: 'post',
				data: query,
			})
		},
		sys_role_edit(query = {}) {
			return request('/admin/role', {
				method: 'put',
				data: query,
			})
		},
		sys_role_del(ids) {
			return request('/admin/role/deleteByIds', {
				method: 'post',
				data: ids,
			})
		},
		sys_role_export(query) {
			return request('/admin/role/sysrole/export', {
				method: 'post',
				data: query,
			})
		},
	}
}
const areaModel = (request) => {
	return {
		admin_sysadministration_name(query) {
			return request('/admin/sysadministration/areaName', {
				method: 'post',
				data: query,
			})
		},
		admin_sysadministration_add(query) {
			return request('/admin/sysadministration', {
				method: 'post',
				data: query,
			})
		},
		admin_sysadministration_edit(query) {
			return request('/admin/sysadministration', {
				method: 'put',
				data: query,
			})
		},
		admin_sysadministration_del(query) {
			return request('/admin/sysadministration/delete', {
				method: 'post',
				data: query,
			})
		},
		admin_sysadministration_tree(query) {
			return request('/admin/sysadministration/tree', {
				method: 'get',
				params: query,
			})
		},
		admin_sysadministration_view(query) {
			return request('/admin/sysadministration/page', {
				method: 'get',
				params: query,
			})
		},
		// 行政区划审批人
		sysadministrationapprover_update(query) {
			return request('/admin/sysadministrationapprover/update', {
				method: 'post',
				data: query,
			})
		},
		// 获取行政区划审批人
		sysadministrationapprover_getList(administrationId) {
			return request('/admin/sysadministrationapprover/getList', {
				method: 'get',
				params: {
					administrationId,
				},
			})
		},
		// 行政地区数据统计
		sysadministration_count() {
			return request('/admin/sysadministration/count', {
				method: 'post',
				data: {},
			})
		},
		// 地区树获取
		sysadministration_getTree(query) {
			return request('/admin/sysadministration/getTree', {
				method: 'post',
				data: query,
			})
		},
		// 通过id查询
		admin_sysadministration_detail(administrationId) {
			return request(`/admin/sysadministration/${administrationId}`, {
				method: 'get',
			})
		},
	}
}
const menuModel = (request) => {
	return {
		// 菜单统计
		admin_sysMenu_count(query = {}) {
			return request('/admin/menu/count', {
				method: 'post',
				data: query,
			})
		},
		admin_menu(query = {}) {
			return request('/admin/menu', {
				method: 'get',
				params: query,
			})
		},
		// 返回当前用户的树形菜单集合在总菜单内的选中
		getSelectMenuInAdmin(query = {}) {
			return request('/admin/menu/getSelectMenuInAdmin', {
				method: 'get',
				params: query,
			})
		},
		//  返回当前用户的树形菜单集合和总菜单
		getSelectMenu(query = {}) {
			return request('/admin/menu/getSelectMenu', {
				method: 'get',
				params: query,
			})
		},
		// 根据指定角色等参数获取树形菜单集合
		getMenuTreeByRoleIds(query = {}) {
			return request('/admin/menu/getMenuTreeByRoleIds', {
				method: 'get',
				params: query,
			})
		},
		sys_menu_add(query = {}) {
			return request('/admin/menu', {
				method: 'post',
				data: query,
			})
		},
		sys_menu_edit(query = {}) {
			return request('/admin/menu', {
				method: 'put',
				data: query,
			})
		},
		sys_menu_del(menuId) {
			return request('/admin/menu/' + menuId, {
				method: 'delete',
			})
		},
		sysServiceOrganization(query = {}) {
			return request('/admin/sysServiceOrganization/getChildren', {
				method: 'get',
				params: {
					classifyId: 2,
					id: -1,
					type: 1,
					...query,
				},
			})
		},
		// 获取服务商用户树
		view_serviceprovider_user(query = {}) {
			return request('/admin/sysServiceOrganization/getProviderUserTree', {
				method: 'get',
				params: {
					classifyId: 5,
					...query,
				},
			})
		},
	}
}
const dictModel = (request) => {
	return {
		//数据字典
		sys_dict_page(query = {}) {
			return request('/admin/dict/page', {
				method: 'post',
				data: query,
			})
		},
		sys_dict_add(query = {}) {
			return request('/admin/dict', {
				method: 'post',
				data: query,
			})
		},
		sys_dict_edit(query = {}) {
			return request('/admin/dict', {
				method: 'put',
				data: query,
			})
		},
		sys_dict_del(ids) {
			return request('/admin/dict/delete', {
				method: 'post',
				data: ids,
			})
		},
		sys_dict_item_page(data) {
			return request('/admin/dict/item/list', {
				method: 'post',
				data: data,
			})
		},
		sys_dict_item_add(data) {
			return request('/admin/dict/item', {
				method: 'post',
				data: data,
			})
		},
		sys_dict_item_edit(data) {
			return request('/admin/dict/item', {
				method: 'put',
				data: data,
			})
		},
		sys_dict_item_delete(id) {
			return request('/admin/dict/item/' + id, {
				method: 'delete',
			})
		},
		getDictItemList(code) {
			return request('/admin/dict/item/getDictItemList', {
				method: 'post',
				data: Array.isArray(code) ? code : [code],
			})
		},
		sys_dict_export(query = {}) {
			return request('/admin/dict/sysdict/export', {
				method: 'post',
				data: {
					...query,
				},
			})
		},
	}
}

// 短信发送模板

export const messageTemplate = (request) => {
	return {
		view_messageTemplate_page(query) {
			return request('/admin/messageTemplate/page', {
				method: 'post',
				data: query,
			})
		},
		view_messageTemplate_add(query) {
			return request('/admin/messageTemplate/add', {
				method: 'post',
				data: query,
			})
		},
		view_messageTemplate_edit(query) {
			return request('/admin/messageTemplate/edit', {
				method: 'post',
				data: query,
			})
		},
		view_messageTemplate_del(query) {
			return request('/admin/messageTemplate/del', {
				method: 'post',
				data: {
					batchesDel: query,
				},
			})
		},
		// 消息通知列表-机构
		view_org_notice_page(query = {}) {
			return request('/admin/sysNoticeRecord/orgNotice/page', {
				method: 'post',
				data: query,
			})
		},
	}
}

export const ssoManage = (request) => {
	return {
		ssoLogin(code: string, token: string) {
			return request('/auth/oauth/token', {
				method: 'post',
				headers: {
					'Content-Type': 'application/x-www-form-urlencoded',
					Authorization: `Basic ${token}`,
				},
				params: {
					grant_type: 'mobile',
					mobile: `SSO@${code}`,
					code: code,
				},
			})
		},
		ssoTokenLogin(token: string) {
			return request('/admin/sso/login', {
				method: 'post',
				headers: {
					'Content-Type': 'application/x-www-form-urlencoded',
				},
				data: {
					authorization: token,
				},
			})
		},
		//测试加解密
		view_sysSsoConfig_testEncrypt(query) {
			return request('/admin/sysSsoConfig/testEncrypt', {
				method: 'post',
				data: query,
			})
		},
		//验证签名
		view_sysSsoConfig_verifySignHex(query) {
			return request('/admin/sysSsoConfig/verifySignHex', {
				method: 'post',
				data: query,
			})
		},
		// 根据ID刷新应用凭证(重新生成)
		view_sysSsoConfig_refreshSysSsoConfig(query) {
			return request('/admin/sysSsoConfig/refreshSysSsoConfig', {
				method: 'post',
				data: query,
			})
		},
		view_sysSsoConfig_page(query) {
			return request('/admin/sysSsoConfig/page', {
				method: 'post',
				data: query,
			})
		},
		view_sysSsoConfig_add(query) {
			return request('/admin/sysSsoConfig/add', {
				method: 'post',
				data: query,
			})
		},
		view_sysSsoConfig_edit(query) {
			return request('/admin/sysSsoConfig/edit', {
				method: 'post',
				data: query,
			})
		},
		view_sysSsoConfig_del(query) {
			return request('/admin/sysSsoConfig/del', {
				method: 'post',
				data: {
					batchesDel: query,
				},
			})
		},
		// 应用访问
		view_sso_ssoRelease(appId) {
			return request(`/admin/sso/release/${appId}`, {
				method: 'get',
			})
		},
		// 获取腾讯云音视频签名
		view_sys_liteAv_sign(userId: string | number) {
			return request(`/admin/liteAv/sign`, {
				method: 'post',
				data: {
					userId,
				},
			})
		},
	}
}

export default ({ request }: any) => ({
	...adminModel(request),
	...userModel(request),
	...dictModel(request),
	...menuModel(request),
	...roleModel(request),
	...areaModel(request),
	...messageTemplate(request),
	...ssoManage(request),
})
